package com.kuang.jdbc;

import org.junit.Test;

import java.awt.dnd.DragGestureEvent;
import java.sql.*;

public class jdbcinsert {
    @Test
    public void insertTest() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");

        String url="jdbc:mysql://localhost:8806/jdbc?UseUnicode=true&characterEncoding=utf-8";
        String username="root";
        String password="123456";

        Connection connection = DriverManager.getConnection(url, username, password);

        String sql="insert into users(id,name,password,email,birthday) values(?,?,?,?,?)";

        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1,2);
        preparedStatement.setString(2,"汪小平");
        preparedStatement.setString(3,"abcdfeg");
        preparedStatement.setString(4,"wxp@qq.com");
        preparedStatement.setDate(5,new Date(new java.util.Date().getTime()));

        int i = preparedStatement.executeUpdate();
        if(i>0){
            System.out.println("插入数据成功");
        }

        preparedStatement.close();
        connection.close();


    }
}
